package springTest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import service.AOP.defineAOP.AroundAopWithParams;
import service.AOP.defineAOP.MainBusiness;
import service.AutowireUseInListMap.BeanInvoke;
import service.IOCInsertType.MessageService;
import service.beanAotuWare.MessageSayService;
import service.jsrAnotation.HelloWorld;
import service.resourceFileGet.TestResource;
import service.testGetConfigFile.GetPropertiesConfig;
import service.beanDefineDemo.BeanDefineByAnnotation;
import design.patterns.factorymode.api.CarFactoryInterface;

import java.io.IOException;

/**
 * Created by cww
 * Date : 2018/5/10
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"file:src/main/resources/spring/appCtx-*.xml"})
public class springInitializedemo {

    /*spring框架直接依赖实现，dubbo则依赖接口
    * IOC控制反转，DI依赖注入，用spring容器来管理MessageService
    * 不需要再创建对象*/
    @Autowired
    private MessageService messageService;

    @Autowired
    private MessageSayService messageSayService;

    @Autowired
    private BeanDefineByAnnotation beanDefineByAnnotation;

    @Autowired
    private BeanDefineByAnnotation beanDefineByAnnotation1;

    @Autowired
    private TestResource testResource;

    @Autowired
    private BeanInvoke beanInvoke;

    @Autowired
    private GetPropertiesConfig getPropertiesConfig;

    @Autowired
    private HelloWorld helloWorld;
    @Test
    public void getMessageTest(){
        System.out.println(messageService.getMessage("hahahhahahahahahahahahh"));
    }

    @Test
    public void testApplicationContext(){

    }

    @Test
    public void testAutoWaire(){
        messageSayService.say("传入的参数");
    }

    @Test
    public void getResource(){
        try {
            testResource.getResource();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * scope
     * bean的作用域测试
     */
    @Test
    public void beanTest(){
        beanDefineByAnnotation.beanTest();
        System.out.println(beanDefineByAnnotation.hashCode());
        beanDefineByAnnotation1.beanTest();
        System.out.println(beanDefineByAnnotation1.hashCode());
    }

    /**
     *
     */
    @Test
    public void autowireTest(){
        beanInvoke.say();
    }

    /**
     * 测试读取配置文件内容
     */
    @Test
    public void  getProperties(){
        getPropertiesConfig.getPropertiesConfig();
    }

    @Test
    public void jsrDemo(){
        helloWorld.printMessage();
    }

    @Autowired
    private MainBusiness mainBusiness;
    @Test
    public void testAOP() throws IOException {
        mainBusiness.main();
    }
    @Autowired
    private AroundAopWithParams aroundAopWithParams;
    @Test
    public void testAOPWithParam(){
        aroundAopWithParams.init1("测试带参环绕通知",110);
        System.out.println("===========================================");
        aroundAopWithParams.init("测试带参环绕通知++++",120);
    }

    @Test
    public void testIntroduction(){
//        WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
//        FilterService filterService = (FilterService)wac.getBean("mainBusiness");
//        filterService.filter();
    }
    @Autowired
    private CarFactoryInterface carFactoryInterface1;
    @Test
    public void get(){
        carFactoryInterface1.manufacture();
    }
}
